package com.th.apicenter.toutiao;

import com.th.apicenter.tools.ThResult;
import com.th.apicenter.toutiao.entity.ThTtData;
import com.th.apicenter.toutiao.service.ToutiaoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author kay
 * @date 2025/6/16
 * @TODO
 */
@RestController
@RequestMapping("/tt")
@Slf4j
public class ToutiaoController {

    @Autowired
    private ToutiaoService toutiaoService;


    @GetMapping("/monitor")
    public ThResult receiveUrl(@RequestParam(name = "adid", required = false) String adid,
                               @RequestParam(name = "advertiser_id", required = false) String advertiser_id,
                               @RequestParam(name = "convert_id", required = false) String convert_id,
                               @RequestParam(name = "request_id", required = false) String request_id,
                               @RequestParam(name = "track_id", required = false) String track_id,
                               @RequestParam(name = "os", required = false) String os,
                               @RequestParam(name = "imei", required = false) String imei,
                               @RequestParam(name = "idfa", required = false) String idfa,
                               @RequestParam(name = "idfa_md5", required = false) String idfa_md5,
                               @RequestParam(name = "oaid", required = false) String oaid,
                               @RequestParam(name = "oaid_md5", required = false) String oaid_md5,
                               @RequestParam(name = "ts", required = false) String ts,
                               @RequestParam(name = "callback_param", required = false) String callback_param,
                               @RequestParam(name = "callback_url", required = false) String callback_url) {
        ThTtData thTtData = new ThTtData();
        thTtData.setAdid(Integer.valueOf(adid));
        thTtData.setAdvertiserId(advertiser_id);
        thTtData.setConvertId(convert_id);
        thTtData.setRequestId(request_id);
        thTtData.setTrackId(track_id);
        thTtData.setOs(os);
        thTtData.setImei(imei);
        thTtData.setIdfa(idfa);
        thTtData.setIdfaMd5(idfa_md5);
        thTtData.setOaid(oaid);
        thTtData.setOaidMd5(oaid_md5);
        thTtData.setTs(ts);
        thTtData.setCallbackParam(callback_param);
        thTtData.setCallbackUrl(callback_url);
        thTtData.setCreateDate(new Date());
        toutiaoService.monitor(thTtData);
        return ThResult.success("cg");
    }
}
